package info.himanshug.www.imageprocessing;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;

abstract public class PointImageFilter implements ImageFilter {

	@Override
	public Bitmap filter(Bitmap src) {
		return filter(src,null);
	}
	
	
	public Bitmap filter(Bitmap src, Bitmap dst) {
		//src = src.copy(Config.ARGB_8888, true);
		int w = src.getWidth();
		int h = src.getHeight();
		
		int[] inPixels = new int[w*h];
		src.getPixels(inPixels, 0, w, 0, 0, w, h);
		
		for(int y = 0; y < h; y++) {
			for(int x = 0; x < w; x++) {
				int idx = (y * w) + x;
				inPixels[idx] = filterRGB(0,0,inPixels[idx]); //0,0 are dummy values here
			}
		}
		
		if(dst == null)
			dst = Bitmap.createBitmap(w, h, Config.ARGB_8888);
		dst.setPixels(inPixels, 0, w, 0, 0, w, h);
		return dst;
	}
	
	abstract protected int filterRGB(int x, int y, int rgb);
}
